# coding=utf-8
import redis as redis_connection
from flask_caching import Cache
from flask_login import LoginManager
from werkzeug.local import LocalProxy
from flask_sqlalchemy import BaseQuery, SQLAlchemy

from flasgger import Swagger

from apps.logconfig import get_log
from apps.a_common.sql import paginate
from config import REDIS_HOST, REDIS_PORT, REDIS_DB, REDIS_PWD


""" 实例化各种扩展，包括flask插件，也包括其他的一些实例，比如redis、minio、普罗米修斯等等 """

log = LocalProxy(get_log)
BaseQuery.paginate = paginate  # cover paginate, 拥有更好的性能。
db = SQLAlchemy()
login_manager = LoginManager()
cache = Cache()
swagger = Swagger()
# 推荐封装在common之中，新建文件，定义key format，其他地方调用函数操作redis
redis = redis_connection.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PWD, decode_responses=True)
